import javax.swing.*;
import java.awt.*;
import java.awt.image.ImageObserver;

/**
 * Created by hasee on 2017/8/23.
 */
public class Node implements ImageObserver {
    int cro; int ver; Dir dir;
    int blocksize= Yard.BLOCK_SIZE;

    public Node(int cro, int ver){
        this.cro=cro;
        this.ver=ver;
    }

    public Node(int cro, int ver, Dir dir){
        this.cro=cro;
        this.ver=ver;
        this.dir=dir;
    }

    public void drawSnakeHead(Graphics g,Dir dir){//画蛇头
        ImageIcon icon = null;
        switch (dir){
            case L:icon=new ImageIcon("image\\head_left.png");break;
            case U:icon=new ImageIcon("image\\head_up.png");break;
            case R:icon=new ImageIcon("image\\head_right.png");break;
            case D:icon=new ImageIcon("image\\head_down.png");break;
        }
        Image image=icon.getImage();
        g.drawImage(image,(ver-1)*blocksize,(cro-1)*blocksize,blocksize,blocksize,this);
    }

    public void drawSnakeBody(Graphics g,Dir dir){//画蛇身
        ImageIcon icon=null;
        switch (dir){
            case L:icon=new ImageIcon("image\\body_left.png");break;
            case U:icon=new ImageIcon("image\\body_up.png");break;
            case R:icon=new ImageIcon("image\\body_left.png");break;
            case D:icon=new ImageIcon("image\\body_up.png");break;
        }
        Image image=icon.getImage();
        g.drawImage(image,(ver-1)*blocksize,(cro-1)*blocksize,blocksize,blocksize,this);
    }

    public void drawCornerBody(Graphics g,Dir befordir,Dir dir,Dir nextdir){
        ImageIcon icon=null;
        if(befordir==Dir.L&&nextdir==Dir.U){
            icon=new ImageIcon("image\\body_down_left.png");
        }
        else if(befordir==Dir.L&&nextdir==Dir.D){
            icon=new ImageIcon("image\\body_up_left.png");
        }
        else if(befordir==Dir.R&&nextdir==Dir.U){
            icon=new ImageIcon("image\\body_down_right.png");
        }
        else if(befordir==Dir.R&&nextdir==Dir.D){
            icon=new ImageIcon("image\\body_up_right.png");
        }
        else if(befordir==Dir.U&&nextdir==Dir.L){
            icon=new ImageIcon("image\\body_up_right.png");
        }
        else if(befordir==Dir.U&&nextdir==Dir.R){
            icon=new ImageIcon("image\\body_up_left.png");
        }
        else if(befordir==Dir.D&&nextdir==Dir.L){
            icon=new ImageIcon("image\\body_down_right.png");
        }
        else if(befordir==Dir.D&&nextdir==Dir.R){
            icon=new ImageIcon("image\\body_down_left.png");
        }
        else return;
        Image image=icon.getImage();
        g.drawImage(image,(ver-1)*blocksize,(cro-1)*blocksize,blocksize,blocksize,this);
    }

    public void drawSnakeTail(Graphics g,Dir dir){//画蛇尾
        ImageIcon icon=null;
        switch (dir){
            case L:icon=new ImageIcon("image\\tail_left.png");break;
            case U:icon=new ImageIcon("image\\tail_up.png");break;
            case R:icon=new ImageIcon("image\\tail_right.png");break;
            case D:icon=new ImageIcon("image\\tail_down.png");break;
        }
        Image image=icon.getImage();
        g.drawImage(image,(ver-1)*blocksize,(cro-1)*blocksize,blocksize,blocksize,this);
    }

    public void drawFood(Graphics g,int Size){//画食物
        ImageIcon icon=new ImageIcon("image\\shi.png");
        Image image=icon.getImage();
        g.drawImage(image,(ver-1)*blocksize,(cro-1)*blocksize,blocksize,blocksize,this);
    }

    @Override
    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
        return false;
    }
}
